#ifndef SUPERUSERSDB_H
#define SUPERUSERSDB_H

#include "CoreFarmAPI.h"


////////////////////////////////////////////////////////
//////Super User NODE AND METHODS///////////////////////
////////////////////////////////////////////////////////

typedef struct SuperUsersNode{

	char userName[USERNAME_LENGTH];
	char userPass[PASS_LENGTH];
	int userType;
	struct SuperUsersNode* next;

}SuperUsersNode;

SuperUsersNode* SuperUsersNodeConstructor(){

	SuperUsersNode *thisNode;

	thisNode = (SuperUsersNode*)malloc(sizeof(SuperUsersNode));
	assertMem(thisNode);

	thisNode->userType = 3;
	thisNode->next = NULL;

	return thisNode;

}

void superUsersNodeSetUserName( SuperUsersNode *thisNode, char *_name) { strcpy( thisNode->userName, _name ); }
void superUsersNodeSetUserPass( SuperUsersNode *thisNode, char *_pass) { strcpy( thisNode->userPass, _pass  ); }
void superUsersNodeSetNext( SuperUsersNode *thisNode, SuperUsersNode *_next) { thisNode->next = _next ;}
char *superUsersNodeGetUserName( SuperUsersNode *thisNode) {return thisNode->userName ;}
char *superUsersNodeGetUserPass( SuperUsersNode *thisNode) {return thisNode->userPass ;}
SuperUsersNode * superUsersNodeGetNext( SuperUsersNode *thisNode) { return thisNode->next ;}

/////////////////////////////////////////////////////////////////////////////////////
//////// Super Users Database List structure and methods ////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

typedef struct SuperUsersDB{

	int size;
	SuperUsersNode *head;

}SuperUsersDB;

SuperUsersDB *superUsers_DB = NULL;

void superUsersDBConstructor(){
	superUsers_DB = (SuperUsersDB*)malloc(sizeof(SuperUsersDB));
	assertMem(superUsers_DB);
	
	superUsers_DB->size = 0;
	superUsers_DB->head = NULL;
}

void superUsersDBSetHead(SuperUsersNode *_head){ superUsers_DB->head = _head ;}
SuperUsersNode* superUsersDBGetHead(){ return superUsers_DB->head ;}
int superUsersDBIsEmpty(){ return (superUsers_DB->size == 0) ;}

void superUsersDBPush(char *_name, char *_pass){

	SuperUsersNode *newSuperUsers = SuperUsersNodeConstructor();

	superUsersNodeSetUserName(newSuperUsers, _name);
	superUsersNodeSetUserPass( newSuperUsers, _pass);

	if ( !superUsers_DB )
		superUsersDBConstructor();

	if( !superUsersDBIsEmpty() )
		newSuperUsers->next = superUsers_DB->head;

	superUsers_DB->head = newSuperUsers;
	superUsers_DB->size++;
}


void superUsersPrintAll(){
	SuperUsersNode *currNode = NULL;

	if ( superUsers_DB )
		currNode = superUsers_DB->head;
	while( currNode ){
		printf("User Name: %s \nPassword: %s.\n",currNode->userName, currNode->userPass);
		currNode = currNode->next;
	}//while
}//Super user PrintALL

#endif